package com.fw.system.web.service.impl;

import com.fw.common.Builder;
import com.fw.common.IdXD;
import com.fw.system.web.dao.TbAmountLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fw.system.web.model.entity.TbAmountLog;
import com.fw.system.web.service.ITbAmountLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 支出收益表 服务实现类
 * </p>
 *
 * @author
 * @since 2021-11-24
 */
@Service
public class TbAmountLogServiceImpl extends ServiceImpl<TbAmountLogMapper, TbAmountLog> implements ITbAmountLogService {

    @Autowired
    private IdXD idXD;

    @Override
    public void saveLog(String userId, String logName, BigDecimal logCount, Integer logType, String imgUrl) {
        TbAmountLog build = Builder.of(TbAmountLog::new)
                .with(TbAmountLog::setId, idXD.nextId())
                .with(TbAmountLog::setUserId, userId)
                .with(TbAmountLog::setLogName, logName)
                .with(TbAmountLog::setLogCount, logCount)
                .with(TbAmountLog::setLogType, logType)
                .with(TbAmountLog::setCreateTime, LocalDateTime.now())
                .with(TbAmountLog::setImgUrl, imgUrl).build();
        if (logType.equals(1) || logType.equals(2))
            build.setIsStatus(1);
        build.insert();
    }
}
